package com.ruoyi.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.admin.domain.Student;
import com.ruoyi.admin.model.request.StudentReq;
import com.ruoyi.admin.service.StudentService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.PageDomainV2;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学生相关接口
 *
 * @author makejava
 * @since 2023-03-25 14:02:26
 */
@RestController
@RequestMapping("system/student")
public class StudentController extends BaseController {

    @Autowired
    private StudentService studentService;

    /**
     * 添加学生
     * @param student
     * @return
     */
    @Log(title = "学生管理", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.checkRole('admin|teacher')")
    @PostMapping("add")
    public AjaxResult add(@Validated @RequestBody StudentReq student){
        return toAjax(studentService.add(student));
    }

    /**
     * 修改学生
     * @param student
     * @return
     */
    @Log(title = "学生管理", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.checkRole('admin|teacher')")
    @PostMapping("edit")
    public AjaxResult edit(@Validated @RequestBody StudentReq student){
        return toAjax(studentService.edit(student));
    }

    /**
     * 学生分页查询
     * @param pageDomain
     * @param student
     * @return
     */
    @PreAuthorize("@ss.checkRole('admin|teacher')")
    @PostMapping("page")
    public TableDataInfo page(PageDomainV2 pageDomain, Student student){
        return studentService.studentPage(buildPage(), student);
    }

}

